package com.example.mychat.controller;

import com.example.mychat.model.Message;
import com.example.mychat.model.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@RestController
public class MessageController {
    @Autowired
    private MessageMapper messageMapper;

    @GetMapping("/message")
    public List<Message> getMessage(int sessionId){
        List<Message> messageBySessionId = messageMapper.getMessageBySessionId(sessionId);
        Collections.reverse(messageBySessionId);
        return messageBySessionId;
    }
}
